package com.xin.appaspectj2;

import android.Manifest;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    String string;

    public void setString(String string) {
        this.string = string;
    }

    public String getString() {
        return string;
    }

    private String getString2() {
        return string;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        findViewById(R.id.camera).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                doCamera();
            }
        });
        findViewById(R.id.method).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                doMethod();
            }
        });
        findViewById(R.id.field).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                doField();
            }
        });
    }

    private void doField() {
        setString("doField");
        log("doField() called " + getString());
        log("doField() called " + getString2());
        log("doField() called " + string);
    }


    private void log(String s) {
        Log.e("MainActivity", s);
    }

    private void doMethod() {
        log("doMethod() called");
    }

    @MPermission(value = Manifest.permission.CAMERA)
    public void doCamera() {
        Toast.makeText(this, "1", Toast.LENGTH_LONG).show();
    }
}
